require(['monitor'], function () {
    var $view = $('#chargerMonitorClass');
    $('#monitor').monitor({
        canId: '28',
        callback: function (data) {
        	loadData(data);
        },
        clearData: function () {
            $view.setViewData({}, 'id');
        }
    });
    
    function loadData(data) {
        $view.setViewData(data, 'id');
        var runSt = data.runSt||"------";
        var runLen = runSt.length;
        //故障等级(无故障、一级、二级、三级)
        $("#faultLevel").removeClass();
        $("#faultLevel").setView(runSt.substr(runLen - 6, 1), [
            {value: 0,css: 'c-green',text: '无故障'},
            {value: 1,css: 'c-yellow',text: '一级故障（严重故障）'},
            {value: 2,css: 'c-yellow',text: '二级故障（普通故障）'},
            {value: 3,css: 'c-yellow',text: '三级故障（报警故障）'}
        ]);
        //通信状态(正常、通信指令超时 or 收到指令异常)
        $("#commSt").removeClass();
        $("#commSt").setView(runSt.substr(runLen - 5, 1), [
            {value: 0,css: 'c-green',text: '正常'},
            {value: 1,css: 'c-yellow',text: '异常'}
        ]);
        //启动状态(电池电压正常可以启动、电池电压异常不允许启动
        $("#startSt").removeClass();
        $("#startSt").setView(runSt.substr(runLen - 4, 1), [
            {value: 0,css: 'c-green',text: '电池电压正常可以启动'},
            {value: 1,css: 'c-yellow',text: '电池电压异常不允许启动'}
        ]);
        //输入电压(正常、输入电压错误，充电机停止工作)
        $("#voltageOut").removeClass();
        $("#voltageOut").setView(runSt.substr(runLen - 3, 1), [
            {value: 0,css: 'c-green',text: '正常'},
            {value: 1,css: 'c-yellow',text: '输入电压错误,充电机停止工作'}
        ]);
        //充电机温度
        $("#chargerTept").removeClass();
        $("#chargerTept").setView(runSt.substr(runLen - 2, 1), [
            {value: 0,css: 'c-green',text: '正常'},
            {value: 1,css: 'c-yellow',text: '充电机温度过高保护'}
        ]);
        //硬件故障(正常、故障)
        $("#hardFault").removeClass();
        $("#hardFault").setView(runSt.substr(runLen - 1, 1), [
            {value: 0,css: 'c-green',text: '正常'},
            {value: 1,css: 'c-yellow',text: '故障'}
        ]);
    }
});